package bishihuizong;

/**
 * 最长非连续回文子序列
 * Created by JiaJia on 2019/9/19 0019.
 */
public class Yuanfudao {
    public static void main(String[] args) {
        String str="acbdvbea";
        System.out.println(longestSubsequence(str));
    }
    private static int longestSubsequence(String s){
        StringBuilder sb=new StringBuilder(s);
        String s2=sb.reverse().toString();
        int n=s.length();
        int[][] dp=new int[n+1][n+1];
        for (int i = 1; i <=n ; i++) {
            for (int j = 1; j <=n ; j++) {
                if (s.charAt(i-1)==s2.charAt(j-1)){
                    dp[i][j]=dp[i-1][j-1]+1;
                }else {
                    dp[i][j]=Math.max(dp[i-1][j],dp[i][j-1]);
                }
            }
        }
        return dp[n][n];
    }
}